<?php
   if(empty($_GET["action"])){
        if(!empty($_GET["quantity"])){
            foreach($_SESSION['cartitem'] as $k => $v) {
                if($_GET["name"] == $k)
                    $_SESSION['cartitem'][$k]['quantity'] = $_GET['quantity'];
            }
            print'<script type="text/javascript">';
            print'location.href = "view_cart.php";';
            print'</script>';
        }
        if(!empty($_POST["quantity"])){
            foreach($_SESSION['cartitem'] as $k => $v) {
                if($_GET["name"] == $k)
                    if($_POST['quantity'] > 0)
                        $_SESSION['cartitem'][$k]['quantity'] = $_POST['quantity'];
            }
            print'<script type="text/javascript">';
            print'location.href = "view_cart.php";';
            print'</script>';
        }
    }
	if(!empty($_GET['action'])){
        foreach($_SESSION['cartitem'] as $i => $v) {
            if($_GET["name"] == $i)
                unset($_SESSION['cartitem'][$i]);
            if(empty($_SESSION['cartitem']))
                unset($_SESSION['cartitem']);
	}
        print'<script type="text/javascript">';
        print'location.href = "view_cart.php";';
        print'</script>';
    }
?>